package com.testing.splogin.service.impl;

import com.testing.splogin.mapper.UserMapper;
import com.testing.splogin.model.Result;
import com.testing.splogin.model.User;
import com.testing.splogin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
UserMapper userMapper;
    @Override
    public Result login(String username, String password) {
        if (username != null && password != null) {
            if (username.length() > 2 && username.length() < 17
                    && password.length() > 2 && password.length() < 17) {
                User user = userMapper.QueryUserByNameAndPwd(username, password);
                System.out.println("查询到的结果是:"+user);
                //查找到的结果有数据就是登录成功。
                if (user!=null) {
                    Result success = new Result();
                    success.setCode(200);
                    success.setMsg("恭喜登录成功");
                    return success;
                } else {
                    return new Result(-2, "用户名密码错误",
                            "输入的用户名是" + username + "密码是:" + password);
                }
            } else {
                return new Result(-3, "用户名密码长度应是3-16位！", "输入的用户名是" + username + "密码是:" + password);
            }
        } else {
            return new Result(-1, "用户名密码不能为空！",
                    "输入的用户名是" + username + "密码是:" + password);

        }
    }
}
